package com.maven.front.task;

import com.maven.front.bean.EduEmailsendHistory;
import com.maven.front.service.emailgli.EduEmailsendHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Id;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import sun.misc.InnocuousThread;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Component
public class MyTask {

    @Autowired
    private EduEmailsendHistoryService eduEmailsendHistoryService;
    @Autowired
    JavaMailSender javaMailSender;

    //每天凌晨1点执行一次
    @Scheduled(cron="0 0 1 * * *")
  /*  @Scheduled(fixedRate = 10000)*/
    public void testTasks() {
        EduEmailsendHistory eduEmailsendHistory=new EduEmailsendHistory();
        eduEmailsendHistoryService.select1(eduEmailsendHistory);


   /*     EduEmailsendHistory eduEmailsendHistory=new EduEmailsendHistory();
        SimpleMailMessage simpleMailMessage=new SimpleMailMessage();
        List<EduEmailsendHistory> list=this.eduEmailsendHistoryService.select1(eduEmailsendHistory);
        System.out.println(list.size()+"---------------");
        System.out.println(list.get(0).getId());
        if(!CollectionUtils.isEmpty(list)){
            //发送者
            simpleMailMessage.setFrom("2430562424@qq.com");
            for (int i=0;i<=list.size();i++){
                //接收者,setTo群发
                simpleMailMessage.setTo(list.get(i).getEmail());
                //设置邮件主题
                simpleMailMessage.setSubject(list.get(i).getTitle());
                //设置邮件主题内容
                simpleMailMessage.setText(list.get(i).getContent());
                //设置时间
                simpleMailMessage.setSentDate(eduEmailsendHistory.getSendTime());
                //发送
                javaMailSender.send(simpleMailMessage);
                eduEmailsendHistory.setSendTime(new Date());
                eduEmailsendHistory.setId(list.get(i).getId());
                eduEmailsendHistoryService.update(eduEmailsendHistory);
            }

        }
*/
    }


}
